{extend name="index/index" /}
{block name="main"}
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>


<div class="content-page">

    <div class="content">

        <div class="page-heading">
            <h1><i class='fa fa-table'></i>广告管理</h1>
            <h3>广告修改</h3></div>

        <div class="row">

            <div class="col-md-12">
                <div class="widget"  >
                    <div class="widget-header transparent" style="margin-bottom:30px;">
                        <h2><strong>Sortable</strong> Table</h2>

                    </div>
                    <div class="widget-content">
                        <div >
                            <form  name="form1" id="form1" class="form-horizontal" action="{:url('admin/poster/update',['id'=>$data['poster_id']])}" method="post">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">广告名</label>
                                    <div class="col-sm-5">
                                        <input type="input" class="form-control" id="name" name="poster_name" value="{$data.poster_name}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">图片</label>
                                    <div class="col-sm-5">
                                        <img  class="img-responsive" src='/static/posterpic/{$data.poster_pic}'>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">修改图片</label>
                                    <div class="col-sm-5">
                                        <input type='file'  name="photo" id="photo" />
                                    </div>
                                </div>
                                <div class="form-group" style="margin-bottom:60px;">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <input type='hidden' name='poster_pic' value='' id='result' placeholder=""></input>
                                        <input type="button" name="b1" value="更改" onclick="fsubmit()" class="btn btn-warning">
                                        <!-- <button type="submit" class="btn btn-default">添加</button> -->
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>





    </div>


</div>

<script type="text/javascript">

    function fsubmit()
    {

        toastr.options = {
        closeButton: true,// 是否显示关闭按钮
        progressBar: true,// 实现显示计时条
        timeOut: "2000",// 自动关闭时间
        positionClass: "toast-top-right"// 提示位置
        // positionClass: "toast-top-full-width"// 提示位置
        // toast-top-full-width 顶端，宽度铺满整个屏幕
        // toast-top-right  顶端右边
        };


        var artName = $('#name').val();
        if(artName.length==0){  

            toastr.error('广告名不能为空');

        }else{
            
                var data = new FormData($('#form1')[0]);
                $.ajax({
                    url: '/admin/poster/server',
                    type: 'POST',
                    data: data,
                    dataType: 'JSON',
                    cache: false,
                    processData: false,
                    contentType: false
                }).done(function(ret){
                    if(ret['isSuccess']){
                        // $('#result').html(ret['photo'] );
                        document.getElementById('result').value = ret['photo'];
                        toastr.success('修改广告成功');
                        setTimeout(function fun(){
                            $('#form1').submit();
                        },2000)
                        // alert('上传成功');

                    }else{

                        toastr.success('修改广告成功');
                        setTimeout(function fun(){
                            $('#form1').submit();
                        },2000)
                        // alert('提交失敗');
                    }
                });
        }
    }
  </script>

{/block}